'use strict';
const qiniu = require('qiniu')
const Controller = require('egg').Controller;

class TokenController extends Controller {
  async getToken() {
    var accessKey = '7YxO-cNyOIHg6I__b56x5brPDR5fuO2vBadMEWx9';
    var secretKey = '3YfhHXv6neeurUnypI0bwnRJ2nz8fHzBOOYRQJrC';
    var mac = new qiniu.auth.digest.Mac(accessKey, secretKey);

    var bucket = 'zhangyunfeng';

    //简单上传凭证
    var options = {
        scope: bucket,
    };
    var putPolicy = new qiniu.rs.PutPolicy(options);
    const token = putPolicy.uploadToken(mac);
    this.ctx.code = 200;
    this.ctx.body = token;
  }
}

module.exports = TokenController;
